package cn.ycl.system.biz.syslog.controller;

import cn.ycl.syslog.OperationEnum;
import cn.ycl.syslog.SystemLog;
import cn.ycl.system.api.syslog.domain.SysLog;
import cn.ycl.system.biz.syslog.service.SysLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 操作日志表(SysLog)表控制层
 *
 * @author yuanchangliang
 * @since 2021-10-08 11:34:12
 */
@RestController
@RequestMapping("/sysLog")
public class SysLogController {
    /**
     * 服务对象
     */
    @Resource
    private SysLogService sysLogService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public SysLog selectOne(Long id) {
        return this.sysLogService.queryById(id);
    }

    /**
     * 插入日志
     */
    @PostMapping("/insert")
    public SysLog insert(@RequestBody SysLog sysLog) throws InterruptedException {
        return sysLogService.insert(sysLog);
    }

    /**
     * 获取前10条数据
     *
     * @return 单条数据
     */
    @GetMapping("/selectAll")
    public List<SysLog> selectAll() {
        return this.sysLogService.queryAllByLimit(0, 10);
    }

    @GetMapping("/getLogPage")
    @SystemLog(value = "进入操作日志", type = OperationEnum.OPERATION_RECORD)
    public PageInfo<SysLog> getLogPage(SysLog sysLog) {
        PageHelper.startPage(sysLog.getPageNum(), sysLog.getPageSize());
        List<SysLog> logPages = sysLogService.getLogPage(sysLog);
        return new PageInfo<>(logPages);
    }

    /**
     * system模块的健康检查接口
     * @return 结果
     */
    @GetMapping("/health")
    public String systemCheck(){
        return "ok";
    }

}
